package com.whw.fy.controller;

import com.whw.fy.entity.Clazz;
import com.whw.fy.entity.Message;
import com.whw.fy.service.ClazzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@Api(tags = "班级模块")
@RestController
@RequestMapping("/api/clazz")
public class ClazzController {

    @Resource
    private ClazzService clazzService;

    @ApiOperation(value = "添加班级信息")
    @PostMapping("/one")
    public Message insert(Clazz clazz) throws ParseException {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (clazz.getStartTimeToString()!=null){
            clazz.setStartTime(simpleDateFormat.parse(clazz.getStartTimeToString()));
        }
        if (clazz.getEndTimeToString()!=null){
            clazz.setEndTime(simpleDateFormat.parse(clazz.getEndTimeToString()));
        }
        return clazzService.insertSelective(clazz);
    }

    @ApiOperation(value = "根据班级id删除班级信息")
    @DeleteMapping("/")
    public Message delete(Integer classId) {
        return clazzService.deleteByPrimaryKey(classId);
    }

    @ApiOperation(value = "根据班级id查看班级信息")
    @GetMapping("/id")
    public Message selectById(Integer classId) {
        return clazzService.selectByPrimaryKey(classId);
    }

    @ApiOperation(value = "根据班级id查看班级内所有学生信息")
    @GetMapping("/id/student")
    public Message selectStudentById(Integer classId) {
        return clazzService.selectStudentById(classId);
    }

    @ApiOperation(value = "获得所有班级内的所有学生信息(学生信息+班级信息组合接口)")
    @GetMapping("/all/student")
    public Message selectStudentAll() {
        return clazzService.selectStudentAll();
    }

    @ApiOperation(value = "根据班级id和班级上课时间获得班级信息")
    @GetMapping("/selectByIdAndTime")
    public Message selectByIdAndTime(int classId,int timeSkcd, int timeSkjc) {
        return clazzService.selectByIdAndTime(classId, timeSkcd, timeSkjc);
    }

    @ApiOperation(value = "根据班级id修改班级信息")
    @PutMapping("/")
    public Message update(Clazz clazz) throws ParseException {
        return clazzService.updateByPrimaryKeySelective(clazz);
    }

    @ApiOperation(value = "获取全部班级信息")
    @GetMapping("/all")
    public Message selectAll(){
        return clazzService.selectAll();
    }


    @ApiOperation(value = "根据教师id获得他负责的全部班级信息")
    @GetMapping("/all/teacherId")
    public Message selectAllByTeachId(int teacherId){
        return clazzService.selectAllByTeachId(teacherId);
    }

    @ApiOperation(value = "根据班级id获得当前班级全部孩子信息(仅有学生信息接口)")
    @GetMapping("/clazzId/studentInfo")
    public Message selectStudentInfoByClazzId(int clazzId){
        return clazzService.selectStudentInfoByClazzId(clazzId);
    }

    @ApiOperation("班级重名判断")
    @GetMapping("/judgement/className")
    public Message judgementClassName(String className){
        return clazzService.judgementClassName(className);
    }

    @ApiOperation(value = "修改班级对班级名称进行验证")
    @GetMapping("/judgement/update/className")
    public Message judgementUpdateClassName(int classId, String className){
        return clazzService.judgementUpdateClassName(classId,className);
    }
}
